/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.businesslogic;

import cn.ekuma.epos.datalogic.I_DataLogicSystem;
import com.openbravo.data.basic.BasicException;
import com.openbravo.pos.bean.Resource;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.ofsm.impl.FileFiniteStateMachineModel;

/**
 *
 * @author Administrator
 */
public class AdminUtil {
    public static Map<String,FileFiniteStateMachineModel> getALLStateMachines(I_DataLogicSystem dlSystem) throws BasicException{
        HashMap<String,FileFiniteStateMachineModel> machineMap=new HashMap<String,FileFiniteStateMachineModel>();
            List<Resource> resList = dlSystem.listResourceByType(Resource.RESOURCETYPE_STATE);
            FileFiniteStateMachineModel stateMachine;
            for(Resource res:resList){
                byte[] bf = res.getContent();
                if (bf != null) {
                  stateMachine=new FileFiniteStateMachineModel();
                  stateMachine.setSafeUnmarshallingMode(true);
                  ByteArrayInputStream btStream = new ByteArrayInputStream(bf);
                try {
                    stateMachine.unmarshal(btStream);
                } catch (Exception ex) {
                   throw new BasicException(ex);
                }
                  machineMap.put(res.getName(),stateMachine);
                }
            }
       return machineMap;
    }
}
